package com.xuecheng.teaching.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.teaching.domain.CommentReply;
import com.xuecheng.teaching.domain.CourseComment;
import com.xuecheng.teaching.service.CommentReplyService;
import com.xuecheng.teaching.service.CourseCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class FeignCourseCommentController {

    @Autowired
    private CourseCommentService courseCommentService;

    @Autowired
    private CommentReplyService commentReplyService;

    @DeleteMapping("/course-comment/{commentId}")
    public ResponseResult deleteComment(@PathVariable("commentId") Integer commentId){
        //调用service删除
        //1.删除评论表
        LambdaQueryWrapper<CourseComment> qw1 = new LambdaQueryWrapper<>();
        qw1.eq(CourseComment::getCommentId,commentId);
        courseCommentService.remove(qw1);
        //2. 删除评论回复表
        LambdaQueryWrapper<CommentReply> qw2 = new LambdaQueryWrapper<>();
        qw2.eq(CommentReply::getCommentId,commentId);
        commentReplyService.remove(qw2);
        //3. 返回
        return ResponseResult.okResult();
    }

}
